<?php
namespace Admin\Controller;
class MenuController extends BaseController {
	public function index(){
        $object=M('Menu');
        import('ORG.Util.Page');			//Page类的引入
        $count=$object->where($where)->count(); //获取符合条件的数据总数count
		$Page=new \Org\Util\Page($count, 10);			//实例化page类，传入数据总数和每页显示10条内容
		$show=$Page->show();
		$list=$object->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('id asc')->select();
        $this->assign('list',$list);
        $this->assign("page",$show);
        $this->display();
	}
    public function editUI(){
        $where = '(pid is null or pid=0)';
		if(I('get.id')){
			$this->assign('object',M('Menu')->where('id='.I('get.id'))->find());
			$where = $where.' and id<>'.I('get.id');
		}
        $this->assign('menulist',M('Menu')->where($where)->select());
        $this->display('editUI');
    }
    public function rightIndex(){
        $id = I('get.id');
		if($id){
            $this->assign('menurightlist',M('Menuright')
    		->field('c.id,c.nickname')
    		->join('LEFT JOIN bs_user c       ON bs_Menuright.userid = c.id')
    		->where('bs_Menuright.menuid='.$id)
    		->select()
             );
            $this->assign('userlist',M('User')->select()
             );
            $this->display();
		}
    }
    public function rightUI(){
        $id = I('get.id');
		if($id){
            $this->assign('userlist',M('User')->select());
            $this->display();
		}
    }
    public function rightOperation(){
        $obj = M('Menuright');
        $obj -> create();
		if($obj->add()){
			$this->success('授权成功',U('index'));
		}else{
			$this->error('修改失败');
		}
    }
    public function editOperation(){
		$Object = M("Menu");   
		$Object->create();
		$id = I('post.id');
		if($id){
			if($Object->save()){
				$this->success('修改成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('修改失败');
			}
		}else{
			if($Object->add()){
				$this->success('添加成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('添加失败');
			}
		}
    }
    public function removeOperation(){
		$Object = M("Menu");
		if($Object->where('id='.I('get.id').'')->delete()){
			$this->success('删除成功',U('index'));
		}else{
			dump($Object->_sql());
			$this->error('删除失败');
		}
    }
}